package com.htc.service;

/**
 * 服务层通用接口
 *
 * @author: htc
 * @date: Created in 15:40 2018/5/23.
 */
public class ServiceResult<T> {
    /**
     * 是否执行成功
     */
    private boolean success;
    /**
     * 描述信息
     */
    private String message;
    /**
     * 接口返回结果
     */
    private T result;

    public ServiceResult(boolean success) {
        this.success = success;
    }

    public ServiceResult(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public ServiceResult(boolean success, String message, T result) {
        this.success = success;
        this.message = message;
        this.result = result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public static <T> ServiceResult<T> success() {
        return new ServiceResult<T>(true);
    }

    public static <T> ServiceResult<T> of(T result) {
        ServiceResult<T> serviceResult = new ServiceResult<T>(true);
        serviceResult.setResult(result);
        return serviceResult;
    }

    public static <T> ServiceResult<T> notFound() {
        return new ServiceResult<T>(false, Message.NOT_FOUND.getValue());
    }

    public enum Message{
        NOT_FOUND("Not Found Resource!"),
        NOT_LOGIN("User not login!")
        ;
        private String value;

        Message(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }
}
